package com.snow.campuslink.bbs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snow.campuslink.bbs.converter.dto.SearchConditionDto;
import com.snow.campuslink.bbs.converter.dto.SelectBbsPostDto;
import com.snow.campuslink.bbs.converter.dto.UpdateBbsPostActionCountDto;
import com.snow.campuslink.bbs.entity.BbsPost;
import com.snow.campuslink.bbs.feign.CommonImageVideoFeignServer;
import com.snow.campuslink.bbs.feign.UserLoginFeignServer;
import com.snow.campuslink.bbs.mapper.BbsPostMapper;
import com.snow.campuslink.bbs.service.IBbsPostService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static cn.hutool.core.bean.BeanUtil.beanToMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Gaosl
 * @since 2021-02-10
 */
@Service
public class BbsPostServiceImpl extends ServiceImpl<BbsPostMapper, BbsPost> implements IBbsPostService {

    @Resource
    private BbsPostMapper bbsPostMapper;

    @Resource
    private UserLoginFeignServer userLoginFeignServer;

    @Resource
    private CommonImageVideoFeignServer commonImageVideoFeignServer;

    @Override
    public List<SelectBbsPostDto> selectBbsPost(SearchConditionDto searchConditionDto) {
        Map<String, Object> map = beanToMap(searchConditionDto, true, true);
        List<SelectBbsPostDto> bbsPostDtos = bbsPostMapper.selectBbsPost(map);
        List<SelectBbsPostDto> collect = bbsPostDtos.stream().map(i -> {
            i.setBbsPostAuthor(userLoginFeignServer.getUsernameById(i.getBbsPostAuthorId()));
            if(i.getIsWithImageVideo()){
                HashMap<String, Object> map1 = new HashMap<>(2);
//                map1.put("")
                commonImageVideoFeignServer.list(map1);
            }
            return i;
        }).collect(Collectors.toList());

        return collect;
    }

    @Override
    public void updateActionCount(UpdateBbsPostActionCountDto updateBbsPostActionCountDto) {
        Map<String, Object> map = beanToMap(updateBbsPostActionCountDto, true, true);
        bbsPostMapper.updateActionCount(map);
    }


}
